package com.yfq.springframework;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 姚凤桥
 * @date 2022/11/12 17:21
 * @description Bean的创建工厂，能够注册、获取bean
 */
public class BeanFactory {
    private Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>();

    /**
     * 注册BeanDefinition
     */
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }

    /**
     * 获取Bean
     */
    public Object getBean(String beanName) {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);

        return beanDefinition != null ? beanDefinition.getBean() : null;
    }

}
